//
//  Person.m
//  GCD的使用
//
//  Created by 伍银荣 on 2021/8/26.
//  Copyright © 2021 com.WYR. All rights reserved.
//

#import "Person.h"

@implementation Person

+(instancetype)sharedPerson {
    static id instance = nil;
    //这样创建的对象是线程不安全的,所以需要加上一把同步锁,加锁会减慢运行的速度
    @synchronized (self) {
        if (instance == nil) {
            instance = [[self alloc]init];
        }
    }
    return instance;
}

+(instancetype)sharedPersonWithOnce {
    static id instance = nil;
    //dispatch_once是线程安全的
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (instance == nil) {
            instance = [[self alloc]init];
        }
    });
    return instance;
}

@end
